<!-- @author Hussein Abo El Seoud -->
<head>
<!--    <script>
        $(document).ready(function(){
            $("a").click(function(event){
                alert("Thanks for visiting!");
            });
        });
    </script>-->
</head>

<h1>Posts</h1>
<table>
    <tr>
        <td>Dashboard</td>
    </tr>


    <!-- Here is where we loop through our $posts array, printing out post info -->
    <?php foreach ($connect as $post): ?>
        <!--It's a 3D array, but each 2D array has only one array -->
        <?php
        $post = $post['0'];
        if ($post['image'] == "") {
            $post['image'] = "http://localhost/default.png";
        }
        //If it's a tweet color it in white
        if ($post['type'] == 'Tweet') {
            ?>
            <tr style="background-color:#FFFFFF"><td>
                    <?php
                    echo $this->Html->image($post['image']) . ' ' . $post['type'] . ' ' . $this->Html->link($post['name'], array('action' => 'view', $post['postid']))
                    . ' ' . $this->Html->link($post['text'], array('action' => 'view', $post['postid'])) . "<br />" .
                    $post['timee'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .
                    $this->Html->image('https://si0.twimg.com/images/dev/cms/intents/icons/reply_hover.png') .
                    $this->Html->link('reply', "javascript:SetReply('@" . $post['twitterName'] . "','" . $post['postid'] . "')") . ' ' . $this->Html->image('https://si0.twimg.com/images/dev/cms/intents/icons/favorite_hover.png');
                    if ($post['favorited_by_us'] == '0') {
                        echo $this->Html->link('favorite', array('controller' => 'Tweets', 'action' => 'favorite', $post['postid'] ,'0')) . ' ';
                    } else {
                        echo $this->Html->link('unfavorite', array('controller' => 'Tweets', 'action' => 'unfavorite', $post['postid'], 0)) . ' ';
                    }
                    echo $this->Html->link('delete', array('action' => 'deletetweet', $post['postid']) , array('confirm' => 'Are you sure you want to delete this ?')). ' ' . $this->Html->link('assign', array('controller' => 'Tasks', 'action' => 'addTask', $post['postid']));
                    ?>

                </td></tr><?php
        }
        //If it's a mention color it in blue
        else if ($post['type'] == 'Mention') {
                    ?>
            <tr style="background-color:#bce8f1"><td>
                    <?php
                    echo $this->Html->image($post['image']) . ' ' . $post['type'] . ' ' . $this->Html->link($post['name'], array('action' => 'view', $post['postid'])) . ' ' .
                    $this->Html->link($post['text'], array('action' => 'view', $post['postid'])) . "<br />" .
                    $post['timee'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .
                    $this->Html->image('https://si0.twimg.com/images/dev/cms/intents/icons/reply_hover.png') .
                    $this->Html->link('reply', "javascript:SetReply('@" . $post['twitterName'] . "','" . $post['postid'] . "')") . ' ' . $this->Html->image('https://si0.twimg.com/images/dev/cms/intents/icons/retweet_hover.png');
                    if ($post['retweeted_by_us'] == '0') {
                        echo $this->Html->link('retweet', array('controller' => 'Tweets', 'action' => 'retweetPermission', $post['postid'], 0), NULL, 'Are you sure you want to retweet this post ?') . ' ';
                    } else {
                        echo $this->Html->link('undo retweet', array('controller' => 'Tweets', 'action' => 'undoRetweet', $post['postid']), NULL) . ' ';
                    }
                    echo $this->Html->image('https://si0.twimg.com/images/dev/cms/intents/icons/favorite_hover.png');
                    if ($post['favorited_by_us'] == '0') {
                        echo $this->Html->link('favorite', array('controller' => 'Tweets', 'action' => 'favorite', $post['postid'] ,'0')) . ' ';
                    } else {
                        echo $this->Html->link('unfavorite', array('controller' => 'Tweets', 'action' => 'unfavorite', $post['postid'], 0)) . ' ';
                    }
                    echo $this->Html->link('assign', array('controller' => 'Tasks', 'action' => 'addTask', $post['postid']));
                    ?>

                </td></tr><?php
        }
        //If it's a DM color it in red
        else if ($post['type'] == 'Direct message') {
                    ?>
            <tr style="background-color:#aaa"><td>
                    <?php
                    echo $this->Html->image($post['image']) . ' ' . $post['type'] . ' ' . $this->Html->link($post['name'], array('action' => 'view', $post['postid'])) . ' ' .
                    $this->Html->link($post['text'], array('action' => 'view', $post['postid'])) . "<br />" .
                    $post['timee'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" .
                    $this->Html->image('https://si0.twimg.com/images/dev/cms/intents/icons/reply_hover.png') .
                    $this->Html->link('reply', array('controller' => 'DirectMessages', 'action' => 'senddm', $post['postid'])) . ' ' .
                    $this->Html->link('delete', array('action' => 'deletedm', $post['postid']),
                array('confirm' => 'Are you sure you want to delete this ?'));
                    ?>
                </td></tr><?php
        }
        //If it's a favorite color it in yellow
        else if ($post['type'] == 'Favorite') {
                    ?>
            <tr style="background-color:#FFE87C"><td>
                    <?php
                    echo $this->Html->image($post['image']) . ' ' . $post['type'] . ' ' . $this->Html->link($post['name'], array('action' => 'view', $post['postid'])) . ' ' .
                    $this->Html->link($post['text'], array('action' => 'view', $post['postid'])) . "<br />" .
                    $post['timee']
                    ?>
                </td> </tr> <?php
        }
        //If it's a retweet color it in green
        else if ($post['type'] == 'Retweet') {
                    ?>
            <tr style="background-color:#57E964"><td>
                    <?php
                    echo $this->Html->image($post['image']) . ' ' . $post['type'] . ' ' . $this->Html->link($post['name'], array('action' => 'view', $post['postid'])) . ' ' .
                    $this->Html->link($post['text'], array('action' => 'view', $post['postid'])) . "<br />" .
                    $post['timee']
                    ?>
                </td></tr> <?php } endforeach; ?>
</table>
<?php $this->start('content1');?>
<div class="well pull-left">
            <ul class="nav nav-list">
                <li><a href="/FutureTweets/viewfuturetweets">View my Tweets</a></li>
                <li><?php echo $this->Html->link('View my Direct Messages' , array('controller' => 'FutureDms', 'action' => 'viewfuturedms')); ?></li>
                 </ul>
        </div>
                <?php $this->end();
                ?>